import 'package:flutter/material.dart';

class TabBarControllerPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => TabBarControllerPageState();
}

class TabBarControllerPageState extends State
    with SingleTickerProviderStateMixin {
  TabController _TabController;

  @override
  void dispose() {
    super.dispose();
    _TabController.dispose();
  }

  @override
  void initState() {
    super.initState();
    _TabController = new TabController(vsync: this, length: 2);
    _TabController.addListener(() {
      print(_TabController.index);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('TabBarControllerPage'),
          bottom: TabBar(controller: _TabController, tabs: [
            Tab(text: '热销'),
            Tab(text: '推荐'),
          ]),
        ),
        body: TabBarView(
            controller: _TabController,
            children: [
              Text('123'),
              Text('456'),
            ]
        )
    );
  }
}
